package com.soento.sample.ssm.controller;

import com.soento.core.lang.*;
import com.soento.sample.ssm.bean.req.SearchReq;
import com.soento.sample.ssm.dao.TestDao;
import com.soento.web.support.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * 示例
 *
 * @author: yantao.zeng
 * @date: 2018-08-08 10:06
 */
@Slf4j
@Controller
public class DemoController extends BaseController {

    @Autowired
    private TestDao testDao;

    @RequestMapping("search")
    @ResponseBody
    public Response search() {
        SearchReq query = new SearchReq();
        query.setName("a");
        Pagination page = new Pagination();
        page.setPageNum(1);
        page.setPageSize(1);
        query.setPagination(page);

        SorterQuery sort = new SorterQuery();
        sort.setField("id");
        sort.setOrder("desc");
        List<SorterQuery> sorts = new ArrayList<>();
        sorts.add(sort);
        query.setSorters(sorts);

        List<FilterQuery> filters = new ArrayList<>();
        FilterQuery filter = new FilterQuery();
        filter.setField("name");
        List<String> values = new ArrayList<>();
        values.add("aa");
        filter.setValues(values);
        filters.add(filter);
        query.setFilters(filters);
        List<Model> list = testDao.selectList(query);
        PageData<Model> resp = new PageData(query.getPagination(), list);
        return success(resp);
    }

}
